{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-01-26T05:42:33.077470600Z",
     "start_time": "2024-01-26T05:42:33.056460700Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    \"l1\":np.random.rand(10)*20,\n",
    "    \"l2\":np.random.rand(10)*100\n",
    "})"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-26T05:52:44.867783700Z",
     "start_time": "2024-01-26T05:52:44.849793600Z"
    }
   },
   "id": "b42c742d33947637"
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "          l1         l2\n0  14.386052  64.314628\n1   2.876450  91.076586\n2  12.688769  43.858040\n3   2.881443  21.735647\n4   8.502410  18.184227\n5  14.934126  71.683640\n6  13.976257  39.658628\n7  10.679694  72.366445\n8  15.601345  31.760418\n9  10.830741  20.229206",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>l1</th>\n      <th>l2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>14.386052</td>\n      <td>64.314628</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2.876450</td>\n      <td>91.076586</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>12.688769</td>\n      <td>43.858040</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2.881443</td>\n      <td>21.735647</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>8.502410</td>\n      <td>18.184227</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>14.934126</td>\n      <td>71.683640</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>13.976257</td>\n      <td>39.658628</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>10.679694</td>\n      <td>72.366445</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>15.601345</td>\n      <td>31.760418</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>10.830741</td>\n      <td>20.229206</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-26T05:52:46.537965200Z",
     "start_time": "2024-01-26T05:52:46.505986900Z"
    }
   },
   "id": "285513b4e3c577a3"
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [],
   "source": [
    "# 归一话\n",
    "def f1(df,*cols):\n",
    "    df_cp = df.copy()\n",
    "    for col in cols:\n",
    "        max_data = df_cp[col].max()\n",
    "        mim_data = df_cp[col].min()\n",
    "        df_cp[col+\"_guiyi\"] = (df_cp[col]-mim_data)/(max_data-mim_data)\n",
    "    return df_cp\n",
    "\n",
    "# Z-score\n",
    "def f2(df,*cols):\n",
    "    df_cp = df.copy()\n",
    "    for col in cols:\n",
    "        mean_data = df_cp[col].mean()#平均值\n",
    "        std_data = df_cp[col].std()#均差\n",
    "        df_cp[col+\"_zc\"] = (df_cp[col]-mean_data)/std_data\n",
    "    return df_cp"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-26T05:54:05.495396Z",
     "start_time": "2024-01-26T05:54:05.442427400Z"
    }
   },
   "id": "6174fd50db44b4cb"
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "          l1         l2  l1_guiyi  l2_guiyi\n0  14.386052  64.314628  0.904495  0.632856\n1   2.876450  91.076586  0.000000  1.000000\n2  12.688769  43.858040  0.771112  0.352215\n3   2.881443  21.735647  0.000392  0.048721\n4   8.502410  18.184227  0.442122  0.000000\n5  14.934126  71.683640  0.947566  0.733951\n6  13.976257  39.658628  0.872291  0.294604\n7  10.679694  72.366445  0.613227  0.743318\n8  15.601345  31.760418  1.000000  0.186250\n9  10.830741  20.229206  0.625097  0.028055",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>l1</th>\n      <th>l2</th>\n      <th>l1_guiyi</th>\n      <th>l2_guiyi</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>14.386052</td>\n      <td>64.314628</td>\n      <td>0.904495</td>\n      <td>0.632856</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2.876450</td>\n      <td>91.076586</td>\n      <td>0.000000</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>12.688769</td>\n      <td>43.858040</td>\n      <td>0.771112</td>\n      <td>0.352215</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2.881443</td>\n      <td>21.735647</td>\n      <td>0.000392</td>\n      <td>0.048721</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>8.502410</td>\n      <td>18.184227</td>\n      <td>0.442122</td>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>14.934126</td>\n      <td>71.683640</td>\n      <td>0.947566</td>\n      <td>0.733951</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>13.976257</td>\n      <td>39.658628</td>\n      <td>0.872291</td>\n      <td>0.294604</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>10.679694</td>\n      <td>72.366445</td>\n      <td>0.613227</td>\n      <td>0.743318</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>15.601345</td>\n      <td>31.760418</td>\n      <td>1.000000</td>\n      <td>0.186250</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>10.830741</td>\n      <td>20.229206</td>\n      <td>0.625097</td>\n      <td>0.028055</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1(df,\"l1\",\"l2\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-26T05:54:06.295082800Z",
     "start_time": "2024-01-26T05:54:06.251105100Z"
    }
   },
   "id": "703e0c02a04fd163"
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "          l1         l2     l1_zc     l2_zc\n0  14.386052  64.314628  0.779435  0.653145\n1   2.876450  91.076586 -1.678153  1.691864\n2  12.688769  43.858040  0.417023 -0.140842\n3   2.881443  21.735647 -1.677087 -0.999484\n4   8.502410  18.184227 -0.476869 -1.137326\n5  14.934126  71.683640  0.896463  0.939160\n6  13.976257  39.658628  0.691934 -0.303835\n7  10.679694  72.366445 -0.011965  0.965662\n8  15.601345  31.760418  1.038931 -0.610390\n9  10.830741  20.229206  0.020287 -1.057954",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>l1</th>\n      <th>l2</th>\n      <th>l1_zc</th>\n      <th>l2_zc</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>14.386052</td>\n      <td>64.314628</td>\n      <td>0.779435</td>\n      <td>0.653145</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2.876450</td>\n      <td>91.076586</td>\n      <td>-1.678153</td>\n      <td>1.691864</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>12.688769</td>\n      <td>43.858040</td>\n      <td>0.417023</td>\n      <td>-0.140842</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2.881443</td>\n      <td>21.735647</td>\n      <td>-1.677087</td>\n      <td>-0.999484</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>8.502410</td>\n      <td>18.184227</td>\n      <td>-0.476869</td>\n      <td>-1.137326</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>14.934126</td>\n      <td>71.683640</td>\n      <td>0.896463</td>\n      <td>0.939160</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>13.976257</td>\n      <td>39.658628</td>\n      <td>0.691934</td>\n      <td>-0.303835</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>10.679694</td>\n      <td>72.366445</td>\n      <td>-0.011965</td>\n      <td>0.965662</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>15.601345</td>\n      <td>31.760418</td>\n      <td>1.038931</td>\n      <td>-0.610390</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>10.830741</td>\n      <td>20.229206</td>\n      <td>0.020287</td>\n      <td>-1.057954</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f2(df,\"l1\",\"l2\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-26T05:54:08.053427800Z",
     "start_time": "2024-01-26T05:54:08.016453Z"
    }
   },
   "id": "42f745e2419e2b38"
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "0     0.893450\n1     0.567884\n2    -0.305830\n3     0.633482\n4    -0.646596\n        ...   \n95    0.670783\n96    1.213034\n97    0.724979\n98   -0.040336\n99   -0.059425\nLength: 100, dtype: float64"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = pd.Series(np.random.randn(100))\n",
    "c"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-26T07:54:27.002829800Z",
     "start_time": "2024-01-26T07:54:26.925857200Z"
    }
   },
   "id": "76ca56a811c6df1d"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "e46bb5b82194f00"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
